#include <iostream>
#include <string.h>
#include <string>
#include <set>
using namespace std;

#define INF 0x3f3f3f3f

const int N = 205;
int n, m;
int ct[N][N];

int main()
{
    cin >> n >> m;
    memset(ct, INF, sizeof(ct));
    while (m--)
    {
        int a, b, cost;
        cin >> a >> b >> cost;
        ct[a][b] = cost;
        ct[b][a] = cost;
    }
    int k;
    cin >> k;
    int minc = INF, ways = 0, pos = 1;
    for (int i = 1; i <= k; i++)
    {
        set<int> st;
        int cnt;
        cin >> cnt;
        int val, last = 0, cost = 0;
        int flag = 1;
        for (int j = 0; j < cnt; j++)
        {
            cin >> val;
            st.insert(val);
            if (ct[last][val] == INF)
            {
                flag = 0;
            }
            cost += ct[last][val];
            last = val;
        }
        cost += ct[last][0];
        if (flag && st.size() == n && cnt == n && (cost < INF))
        {
            ways++;
            if (cost < minc)
            {
                minc = cost;
                pos = i;
            }
        }
    }
    cout << ways << endl;
    cout << pos << " " << minc;
    return 0;
}